package com.itheima.test16;

import java.util.Comparator;
import java.util.TreeSet;
//25
public class StudentDemo {

    public static void main(String[] args) {
        TreeSet<Student> ts = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result =  o2.getAge()-o1.getAge() ;
                result = result == 0 ? o1.getId().compareTo(o2.getId()) :result;
                return result;
            }
        });
        ts.add(new Student("张三",18,"heima001"));
        ts.add(new Student("李四",18,"heima002"));
        ts.add(new Student("王五",17,"heima003"));
        ts.forEach(s-> System.out.println(s));

    }
}
